package com.cn.dao;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import sun.applet.Main;

/**
 * 数据库连接类
 * 
 */
public class BaseDao {
	protected Connection con;

	protected PreparedStatement psta;

	protected ResultSet rst;

	/**
	 *  得到数据库连接connection对象
	 * @return con
	 */
	public Connection getCon() {

		try {
			// 驱动加载
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/gooddoc?"
					+ "user=root&password=sa&useUnicode=true&characterEncoding=UTF8";
			con = DriverManager.getConnection(url);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}

	public void closeAll() {
		try {
			if (rst != null) {
				rst.close();
			}
			if (psta != null) {
				psta.close();
			}
			if (con != null) {
				con.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
   //测试
	public static void main(String[] args) {
		BaseDao base = new BaseDao();
		System.out.println(base.getCon());
	}
}
